/** 
* @Title: TraditionalThread.java 
* @Package com.lh.threadtest 
* @Description: TODO
* @author Liu 
* @date 2018年1月15日 下午3:28:20 
* @version V1.0 
*/
package com.lh.threadtest.t1;

import java.util.concurrent.TimeUnit;

/** 
* @ClassName: TraditionalThread 
* @Description: 传统线程技术
* @author Liu
* @date 2018年1月15日 下午3:28:20 
*  
*/
public class TraditionalThread {

	/***
	* @Title: main 
	* @Description: TODO
	* @param @param args
	* @return void
	* @throws 
	*/
	public static void main(String[] args) {
		//创建一个线程(执行线索)
		Thread thread = new Thread(){
			@Override
			public void run() {
				while(true){
					System.out.println("1-" + Thread.currentThread().getName());
					//不推荐
					System.out.println("2-" + this.getName());
					
					try {
						TimeUnit.SECONDS.sleep(1);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					
				}
			}
		};
		thread.start();

		Thread thread2 = new Thread(new Runnable() {
			
			public void run() {
				while(true){
					System.out.println("11-" + Thread.currentThread().getName());
					try {
						TimeUnit.SECONDS.sleep(1);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});
		thread2.start();
		
		//new Thread(new Runnable(){..}){..run()..}.start();
		/*
		 * Thread中run()的源码方法:
		 * @Override public void run() { 
			 * if (target != null){ 
			 * 		target.run(); 
			 * } 
		 * }
		 * 
		 * 如果{..run()..}run方法体不为空，Thread中的run()方法将被覆盖，执行
		 * {..run()..}中的run方法；反之，将执行Runnable中的run方法
		 */
		new Thread(
				new Runnable() {
					
					public void run() {
						while(true){
							System.out.println("Runnable: " + Thread.currentThread().getName());
							try {
								TimeUnit.SECONDS.sleep(1);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						}
					}
				}
			){
			@Override
			public void run() {
				while(true){
					System.out.println("Thread: " + Thread.currentThread().getName());
					try {
						TimeUnit.SECONDS.sleep(1);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
	}

}
